<!--
 * @Author: g05047
 * @Date: 2022-02-19 13:54:35
 * @LastEditors: g05047
 * @LastEditTime: 2022-03-03 09:30:54
 * @Description: file content
-->
<template>
  <div class="page">
    <div>
      <h2>接触进口冷链食品统计分析</h2>
    </div>
    <!-- 查询条件 -->
    <el-row :gutter="10" style="margin: 20px 0px">
      <el-col :span="2">
        <el-select
          size="small"
          v-model="queryParam.areaCode"
          placeholder="地区"
        >
          <el-option
            v-for="item in areaOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="4">
        <el-cascader
          :options="statusOptions"
          v-model="queryParam.bodyindustry"
          size="small"
          :props="{ checkStrictly: true }"
          placeholder="请选择单位业态"
          clearable
        >
        </el-cascader>
      </el-col>
      <el-col :span="25">
        <el-date-picker
          v-model="selectedDate"
          type="daterange"
          size="small"
          width="100%"
          range-separator="—"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="handelChangeDate"
        >
        </el-date-picker>
      </el-col>
      <!-- <el-col :span="3">
        <el-select
          size="small"
          v-model="queryParam.status"
          placeholder="核酸采样填报"
          clearable
        >
          <el-option
            v-for="item in collectionOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-col> -->
      <el-col :span="5">
        <el-input
              maxlength="50"
          size="small"
          v-model="queryParam.search"
          placeholder="企业单位名称/统一社会信用代码"
          clearable
        ></el-input>
      </el-col>
      <el-col :span="2" class="btn">
        <el-button type="primary" size="small" @click="handleQuery">
          查询
        </el-button>
      </el-col>
    </el-row>

    <el-tabs type="border-card" v-model="tabName">
      <!-- 区域统计 -->
      <el-tab-pane label="区域统计" name="1">
        <el-row style="margin-bottom: 10px">
          <el-button
            size="small"
            @click="exportExcelArea"
            :loading="exportLoadingArea"
          >
            数据导出
          </el-button>
        </el-row>
        <!-- 区域统计数据 -->
        <el-table
          border
          stripe
          :data="areaTableData"
          :summary-method="handelSum"
          show-summary
          style="width: 100%"
        >
          <el-table-column
            prop="districtName"
            label="区域名称"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="registerTotal"
            label="注册单位数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="staffTotal"
            label="员工人数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="shouldAdoptTotal"
            label="应采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidBatchTotal"
            label="总采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidFillInTotal"
            label="如期采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="supplementaryRecordingTotal"
            label="延期补录批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">
                {{ scope.row.supplementaryRecordingTotal }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nucleicAcidAbnormalTotal"
            label="延期异常批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop=" notFilledInTotal"
            label="正常未填报批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.notFilledInTotal }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

      <!-- 单位业态统计 -->
      <el-tab-pane label="单位业态统计" name="2">
        <el-row style="margin-bottom: 10px">
          <el-button
            size="small"
            @click="exportExcelAreaBodyindustry"
            :loading="exportLoadingBodyindustry"
          >
            数据导出
          </el-button>
        </el-row>
        <!-- 单位业态统计数据 -->
        <el-table
          border
          stripe
          :data="bodyindustryTableData"
          style="width: 100%"
          :summary-method="handelSum"
          show-summary
        >
          <el-table-column
            prop="bodyindustry"
            label="单位业态"
            align="center"
            show-overflow-tooltip
            width="130px"
          >
          </el-table-column>
          <el-table-column
            prop="registerTotal"
            label="注册单位数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <!-- <el-table-column
            label="接触进口冷链食品员工分析"
            align="center"
            show-overflow-tooltip
          > -->
          <el-table-column
            prop="staffTotal"
            label="员工人数"
            align="center"
            show-overflow-tooltip
          >
            <!-- <template slot-scope="scope">
              <span class="green">{{ scope.row.staffTotal }}</span>
            </template> -->
          </el-table-column>
          <el-table-column
            prop="shouldAdoptTotal"
            label="应采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidBatchTotal"
            label="总采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidFillInTotal"
            label="如期采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="supplementaryRecordingTotal"
            label="延期补录批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{
                scope.row.supplementaryRecordingTotal
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nucleicAcidAbnormalTotal"
            label="延期异常批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="notFilledInTotal"
            label="正常未填报批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.notFilledInTotal }}</span>
            </template>
          </el-table-column>
          <!-- </el-table-column> -->
          <!-- <el-table-column
            label="核酸采样信息分析"
            align="center"
            show-overflow-tooltip
          >

            <el-table-column
              prop="nucleicAcidBatchTotal"
              label="总填报批次数"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="green">{{ scope.row.nucleicAcidBatchTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="nucleicAcidFillInTotal"
              label="如期填报数"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="green">{{ scope.row.nucleicAcidFillInTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="supplementaryRecordingTotal"
              label="延期补录数"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="red">{{ scope.row.supplementaryRecordingTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="nucleicAcidAbnormalTotal"
              label="延期异常"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
        </template>
            </el-table-column>
          </el-table-column> -->
        </el-table>
      </el-tab-pane>

      <!-- 注册单位统计 -->
      <el-tab-pane label="注册单位统计" name="3">
        <el-row style="margin-bottom: 10px">
          <el-button
            size="small"
            @click="handelExport"
            :loading="exportLoadingUnit"
          >
            数据导出
          </el-button>
        </el-row>
        <!-- 注册单位统计数据 -->
        <el-table border stripe :data="unitTableData" style="width: 100%">
          <el-table-column
            prop="districtStreet"
            label="区域街道"
            align="center"
            show-overflow-tooltip
            width="170px"
          >
          </el-table-column>
          <el-table-column
            prop="bodyindustry"
            label="单位业态"
            align="center"
            show-overflow-tooltip
            width="130px"
          >
          </el-table-column>
          <el-table-column
            prop="bodyindustryremarks"
            label="单位业态备注"
            align="center"
            show-overflow-tooltip
            width="180px"
          >
            <template slot-scope="scope">
              <span>{{
                scope.row.bodyindustryremarks === ""
                  ? "--"
                  : scope.row.bodyindustryremarks
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="identify"
            label="统一社会信用代码"
            align="center"
            show-overflow-tooltip
            width="170px"
          >
          </el-table-column>
          <el-table-column
            prop="unitname"
            label="注册单位名称"
            align="center"
            show-overflow-tooltip
            width="190px"
          >
          </el-table-column>
          <el-table-column
            prop="newlicenseno"
            label="许可证编号"
            align="center"
            show-overflow-tooltip
            width="150px"
          >
            <template slot-scope="scope">
              <span>
                {{
                  scope.row.newlicenseno === "" ? "--" : scope.row.newlicenseno
                }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="staffTotal"
            label="员工人数"
            align="center"
            show-overflow-tooltip
          >
            <!-- <template slot-scope="scope">
              <span class="green">{{ scope.row.staffTotal }}</span>
            </template> -->
          </el-table-column>
          <el-table-column
            prop="shouldAdoptTotal"
            label="应采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidBatchTotal"
            label="总采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <!-- <el-table-column
            label="核酸采样信息登记情况-食品员工分析"
            align="center"
            show-overflow-tooltip
          > -->
          <el-table-column
            prop="nucleicAcidFillInTotal"
            label="如期采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="supplementaryRecordingTotal"
            label="延期补录批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{
                scope.row.supplementaryRecordingTotal
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nucleicAcidAbnormalTotal"
            label="延期异常批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="notFilledInTotal"
            label="正常未填报批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.notFilledInTotal }}</span>
            </template>
          </el-table-column>
          <!-- </el-table-column> -->
          <!--
          <el-table-column=
            label="核酸采样信息分析"
            align="center"
            show-overflow-tooltip
          >
            <el-table-column
              prop="nucleicAcidBatchTotal"
              label="总填报批次数"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="green">{{ scope.row.nucleicAcidBatchTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="nucleicAcidFillInTotal"
              label="如期填报数"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="green">{{ scope.row.nucleicAcidFillInTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="supplementaryRecordingTotal"
              label="延期补录数"
              align="center"
              show-overflow-tooltip
            >
                <template slot-scope="scope">
          <span class="red">{{ scope.row.supplementaryRecordingTotal }}</span>
        </template>
            </el-table-column>
            <el-table-column
              prop="nucleicAcidAbnormalTotal"
              label="延期异常"
              align="center"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
          <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
        </template>
            </el-table-column>
          </el-table-column=> -->
        </el-table>

        <!-- 注册单位统计分页 -->
        <el-pagination
          style="float: right; margin-top: 20px"
          @current-change="changeCurrentPage"
          :page-size="pageSize"
          background
          layout="total, prev, pager, next"
          :total="listTotal"
          v-if="listTotal > 0"
        >
        </el-pagination>
      </el-tab-pane>

      <!-- 采样日期分析 -->
      <el-tab-pane label="采样日期分析" name="4">
        <el-row style="margin-bottom: 10px">
          <el-col :span="9" style="display: flex; align-items: center">
            <el-radio
              v-model="dateCategory"
              :label="-1"
              @change="changeDateCategory"
            >
              日报
            </el-radio>
            <el-radio
              v-model="dateCategory"
              :label="1"
              @change="changeDateCategory"
            >
              月报
            </el-radio>
            <el-select
              v-if="dateCategory === 1"
              size="small"
              v-model="selectedYear"
              placeholder="年份"
              style="margin-right: 20px"
            >
              <el-option
                v-for="item in yearOptions"
                :key="item.value"
                :label="item.value"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <el-radio
              v-model="dateCategory"
              :label="2"
              @change="changeDateCategory"
            >
              年报
            </el-radio>
            <el-button
              size="small"
              @click="exportExcelCollection"
              :loading="exportLoadingCollection"
              style="margin-left: 20px"
            >
              数据导出
            </el-button>
          </el-col>
        </el-row>
        <!-- 核酸采集填报日期分析数据 -->
        <el-table
          border
          stripe
          :data="collectionTableData"
          style="width: 100%"
          :summary-method="handelSum"
          show-summary
        >
          <el-table-column
            prop="categoryDate"
            label="日期类别"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <!-- <el-table-column
            label="核酸采样信息分析"
            align="center"
            show-overflow-tooltip
          > -->
          <el-table-column
            prop="shouldAdoptTotal"
            label="应采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidBatchTotal"
            label="总采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="nucleicAcidFillInTotal"
            label="如期采样批次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="supplementaryRecordingTotal"
            label="延期补录批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{
                scope.row.supplementaryRecordingTotal
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nucleicAcidAbnormalTotal"
            label="延期异常批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.nucleicAcidAbnormalTotal }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="notFilledInTotal"
            label="正常未填报批次数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="red">{{ scope.row.notFilledInTotal }}</span>
            </template>
          </el-table-column>
          <!-- </el-table-column> -->
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { groupArea } from "@/api/modules/enterprise";
export default {
  data() {
    return {
      // areaOptions: [
      //   {
      //     value: "320500",
      //     label: "苏州市",
      //   },
      //   {
      //     value: "320506",
      //     label: "吴中区",
      //   },

      //   {
      //     value: "320507",
      //     label: "相城区",
      //   },
      //   {
      //     value: "320505",
      //     label: "高新区",
      //   },
      //   {
      //     value: "320508",
      //     label: "姑苏区",
      //   },
      //   {
      //     value: "320509",
      //     label: "工业园区",
      //   },
      //   {
      //     value: "320581",
      //     label: "常熟市",
      //   },
      //   {
      //     value: "320582",
      //     label: "张家港市",
      //   },
      //   {
      //     value: "320583",
      //     label: "昆山市",
      //   },
      //   {
      //     value: "320584",
      //     label: "吴江区",
      //   },
      //   {
      //     value: "320585",
      //     label: "太仓市",
      //   },
      //   {
      //     value: "320592",
      //     label: "张家港保税区",
      //   },
      // ], //地区
      areaOptions: [],
      statusOptions: [
        {
          value: "食品生产经营者",
          label: "食品生产经营者",
        },
        {
          value: "食品流通经营者",
          label: "食品流通经营者",
        },
        {
          value: "餐饮服务经营者",
          label: "餐饮服务经营者",
          children: [
            {
              value: "集体用餐配送或中央厨房",
              label: "集体用餐配送或中央厨房",
            },
            {
              value: "特大型餐饮",
              label: "特大型餐饮",
            },
            {
              value: "大型餐饮",
              label: "大型餐饮",
            },
            {
              value: "中型餐饮",
              label: "中型餐饮",
            },
            {
              value: "小型餐饮",
              label: "小型餐饮",
            },
            {
              value: "微型餐饮",
              label: "微型餐饮",
            },
            {
              value: "其他餐饮",
              label: "其他餐饮",
            },
          ],
        },
        {
          value: "单位食堂",
          label: "单位食堂",
          children: [
            {
              value: "幼托机构食堂",
              label: "幼托机构食堂",
            },
            {
              value: "学校食堂",
              label: "学校食堂",
            },
            {
              value: "养老机构食堂",
              label: "养老机构食堂",
            },
            {
              value: "工地食堂",
              label: "工地食堂",
            },
            {
              value: "机关企事业单位食堂",
              label: "机关企事业单位食堂",
            },
            {
              value: "其他食堂",
              label: "其他食堂",
            },
          ],
        },
        {
          value: "食品销售经营者",
          label: "食品销售经营者",
          children: [
            {
              value: "食品批发销售商",
              label: "食品批发销售商",
            },
              {
              value: "食品批发配送商",
              label: "食品批发配送商",
            },
            {
              value: "商场超市",
              label: "商场超市",
            },
            {
              value: "食杂店",
              label: "食杂店",
            },
            
          ],
        },
      ], //业态
      // collectionOptions: [
      //   { label: "如期填报", value: 1 },
      //   { label: "延期补录", value: 2 },
      //   { label: "延期异常", value: 0 },
      // ], //核酸采样状态
      selectedDate: [], //查询日期
      yearOptions: [], //年份
      queryParam: {
        areaCode: "320500", //区域编码
        bodyindustry: "", //主体业态
        // status: "", //核酸采样填报,采样状态 1如期采样 2延期补录 0延期异常 默认-1
        // pageIndex: 1, //开始页码
        // pageSize: 20, //每页记录条数
        search: "", //搜索(单位名称/社会信用代码)
        endDateCompletion: "", //结束时间(采样时间)
        startDateCompletion: "", //开始时间(采样时间)
      }, //查询参数

      areaTableData: [], //区域表格数据
      areaTableDataCopy: [],
      bodyindustryTableData: [], //业态表格数据
      bodyindustryTableDataCopy: [],
      unitTableData: [], //注册单位表格数据
      collectionTableData: [], //核酸采集表格数据
      collectionTableDataCopy: [],

      dateCategory: -1, //核酸采样类别-1(日报(18),月报1(02-18),年报2(2022-02-18))
      selectedYear: "", //采样日期分析 年份

      exportLoading: false, //导出loading

      tabName: "1", //当前标签名

      pageSize: 20, //注册单位每页条数
      listTotal: 0, //注册单位总条数

      exportLoadingArea: false, //区域等待
      exportLoadingBodyindustry: false, //业态等待
      exportLoadingUnit: false, //单位等待
      exportLoadingCollection: false, //核算采集等待

      areaSums: [],
      bodyindustrySums: [],
      collectionDateSums: [],
    };
  },
  created() {
    this.queryParam.areaCode = this.$route.query.code|| "320500";
    this.findAreaListNoParentByParentCode();

    this.selectedDate = [
      this.$moment().subtract(6, "days").format("YYYY-MM-DD"),
      this.$moment().format("YYYY-MM-DD"),
    ];
    this.queryParam.startDateCompletion = this.selectedDate[0];
    this.queryParam.endDateCompletion = this.selectedDate[1];

    for (let i = 2022; i <= new Date().getFullYear(); i++) {
      this.yearOptions.push({
        value: i,
      });
    }

    this.selectedYear = new Date().getFullYear();

    this.getAreaStatistics();
    this.getBodyindustryStatistics();
    this.getUnitStatistics(1);
    this.getCollectionDateStatistics();
  },
  methods: {
    //获取区域列表
    findAreaListNoParentByParentCode() {
      groupArea({
        params: {
          areaCode: this.queryParam.areaCode,
        },
      }).then((res) => {
        // this.areaOptions = [res.data];
        console.log("获取区域列表", res.data);
        this.areaOptions.push({
          label: res.data.areaName,
          value: res.data.areaCode,
        });
        res.data.children.forEach((item1) => {
          this.areaOptions.push({
            label: item1.areaName,
            value: item1.areaCode,
          });
        });
      });
    },

    //选择日期
    handelChangeDate() {
      this.queryParam.startDateCompletion = this.selectedDate[0];
      this.queryParam.endDateCompletion = this.selectedDate[1];
    },

    //改变日期类别
    changeDateCategory(val) {
      console.log(val);

      this.getCollectionDateStatistics();
    },

    //表格合计
    handelSum(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));

        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        sums[index];
      });

      if (param.columns.length > 0) {
        // console.log(param.columns[0].label);
        if (param.columns[0].label === "区域名称") {
          this.areaSums = sums;
        }
        if (param.columns[0].label === "单位业态") {
          this.bodyindustrySums = sums;
        }
        if (param.columns[0].label === "日期类别") {
          this.collectionDateSums = sums;
        }
      }
      return sums;
    },

    //查询
    handleQuery() {
      console.log(this.tabName);
      if (this.tabName === "1") {
        this.getAreaStatistics();
      }
      if (this.tabName === "2") {
        this.getBodyindustryStatistics();
      }
      if (this.tabName === "3") {
        this.getUnitStatistics(1);
      }
      if (this.tabName === "4") {
        this.getCollectionDateStatistics();
      }
    },

    //分页
    changeCurrentPage(val) {
      this.getUnitStatistics(val);
    },

    //获取区域统计
    getAreaStatistics() {
      let params = JSON.parse(JSON.stringify(this.queryParam));
      // if (params.status === "") {
      //   params.status = -1;
      // }
      if (params.bodyindustry) {
        params.bodyindustry =
          // params.bodyindustry[params.bodyindustry.length - 1];
          params.bodyindustry[0];
      }

      this.$http.getAreaStatistics(params).then((res) => {
        console.log("获取区域统计", res);
        const { code, data, msg } = res;
        if (code === 200) {
          this.areaTableData = data;
        } else {
          this.$message.error(msg);
        }
      });
    },

    //获取单位业态统计
    getBodyindustryStatistics() {
      let params = JSON.parse(JSON.stringify(this.queryParam));
      // if (params.status === "") {
      //   params.status = -1;
      // }
      if (params.bodyindustry) {
        params.bodyindustry =
          // params.bodyindustry[params.bodyindustry.length - 1];
          params.bodyindustry[0];
      }

      this.$http.getBodyindustryStatistics(params).then((res) => {
        console.log("获取单位业态统计", res);
        const { code, data, msg } = res;
        if (code === 200) {
          this.bodyindustryTableData = data;
        } else {
          this.$message.error(msg);
        }
      });
    },

    //获取注册单位统计
    getUnitStatistics(pageIndex) {
      let params = JSON.parse(JSON.stringify(this.queryParam));
      // if (params.status === "") {
      //   params.status = -1;
      // }
      if (params.bodyindustry) {
        params.bodyindustry =
          // params.bodyindustry[params.bodyindustry.length - 1];
          params.bodyindustry[0];
      }
      params.pageIndex = pageIndex;
      params.pageSize = this.pageSize;

      this.$http.getUnitStatistics(params).then((res) => {
        console.log("获取注册单位统计", res);
        const { code, data, msg } = res;
        if (code === 200) {
          this.unitTableData = data.list;
          this.listTotal = data.total;
        } else {
          this.$message.error(msg);
        }
      });
    },

    //核酸采集填报日期统计
    getCollectionDateStatistics() {
      let params = JSON.parse(JSON.stringify(this.queryParam));
      // if (params.status === "") {
      //   params.status = -1;
      // }
      if (params.bodyindustry) {
        params.bodyindustry =
          // params.bodyindustry[params.bodyindustry.length - 1];
          params.bodyindustry[0];
      }
      params.category = this.dateCategory;
      params.year = this.selectedYear;

      this.$http.getCollectionDateStatistics(params).then((res) => {
        console.log("核酸采集填报日期统计", res);
        const { code, data, msg } = res;
        if (code === 200) {
          this.collectionTableData = data;
        } else {
          this.$message.error(msg);
        }
      });
    },

    //导出注册单位
    handelExport() {
      this.exportLoadingUnit = true;
      let params = JSON.parse(JSON.stringify(this.queryParam));
      // if (params.status === "") {
      //   params.status = -1;
      // }
      if (params.bodyindustry) {
        params.bodyindustry =
          // params.bodyindustry[params.bodyindustry.length - 1];
          params.bodyindustry[0];
      }
      params.pageIndex = 1;
      params.pageSize = this.pageSize;

      this.$http.exportRegisterUnit(params).then((res) => {
        var blob = new Blob([res], {
          type: "application/vnd.ms-excel;charset=utf-8",
        });
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download =
          "接触进口冷链食品统计分析_注册单位统计_" +
          new Date().getTime() +
          ".xlsx"; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象

        this.exportLoadingUnit = false;
      });
    },

    //导出区域表格
    exportExcelArea() {
      console.log(this.areaSums);
      this.areaTableDataCopy = JSON.parse(JSON.stringify(this.areaTableData));
      this.areaTableDataCopy.push({
        districtName: this.areaSums[0],
        registerTotal: this.areaSums[1],
        staffTotal: this.areaSums[2],
        shouldAdoptTotal: this.areaSums[3],
        nucleicAcidBatchTotal: this.areaSums[4],
        nucleicAcidFillInTotal: this.areaSums[5],
        supplementaryRecordingTotal: this.areaSums[6],
        nucleicAcidAbnormalTotal: this.areaSums[7],
        notFilledInTotal: this.areaSums[8],
      });
      this.exportLoadingArea = true;
      import("@/utils/Export2Excel").then((excel) => {
        // const multiHeader = [
        //   [
        //     "区域名称",
        //     "注册单位数",
        //     "接触进口冷链食品员工分析",
        //     "",
        //     "",
        //     "",
        //     "",
        //     "核酸采样信息分析",
        //     "",
        //     "",
        //     "",
        //   ], //第一行表头
        // ];
        const tHeader = [
          // "",
          // "",
          // "员工总数",
          // "如期填报",
          // "延期补录",
          // "延期异常",
          // "暂未填报",
          // "总填报批次数",
          // "如期填报数",
          // "延期补录数",
          // "延期异常",
          "区域名称",
          "注册单位数",
          "员工人数",
          "应采样批次数",
          "总采样批次数",
          "如期采样批次数",
          "延期补录批次数",
          "延期异常批次数",
          "正常未填报批次数",
        ]; //最后一行的表头

        const filterVal = [
          // "districtName",
          // "registerTotal",
          // "staffTotal",
          // "foodStaffFillInTotal",
          // "aryRecordingTotal",
          // "foodStaffAbnormalTotal",
          // "foodStaffNotFilledInTotal",
          // "nucleicAcidBatchTotal",
          // "nucleicAcidFillInTotal",
          // "supplementaryRecordingTotal",
          // "nucleicAcidAbnormalTotal",
          "districtName",
          "registerTotal",
          "staffTotal",
          "shouldAdoptTotal",
          "nucleicAcidBatchTotal",
          "nucleicAcidFillInTotal",
          "supplementaryRecordingTotal",
          "nucleicAcidAbnormalTotal",
          "notFilledInTotal",
        ];

        const data = this.formatJson(filterVal, this.areaTableDataCopy);
        // const merges = ["A1:A2", "B1:B2", "C1:G1", "H1:K1"];
        excel.export_json_to_excel({
          // multiHeader,
          header: tHeader,
          filename: "区域统计_" + new Date().getTime(),
          data,
          // merges,
        });

        //导出excel后
        this.exportLoadingArea = false;
      });
    },

    //导出单位业态表格
    exportExcelAreaBodyindustry() {
      console.log(this.bodyindustrySums);
      this.bodyindustryTableDataCopy = JSON.parse(
        JSON.stringify(this.bodyindustryTableData)
      );
      this.bodyindustryTableDataCopy.push({
        bodyindustry: this.bodyindustrySums[0],
        registerTotal: this.bodyindustrySums[1],
        staffTotal: this.bodyindustrySums[2],
        shouldAdoptTotal: this.bodyindustrySums[3],
        nucleicAcidBatchTotal: this.bodyindustrySums[4],
        nucleicAcidFillInTotal: this.bodyindustrySums[5],
        supplementaryRecordingTotal: this.bodyindustrySums[6],
        nucleicAcidAbnormalTotal: this.bodyindustrySums[7],
        notFilledInTotal: this.bodyindustrySums[8],
      });
      this.exportLoadingBodyindustry = true;
      import("@/utils/Export2Excel").then((excel) => {
        // const multiHeader = [
        //   [
        //     "单位业态",
        //     "注册单位数",
        //     "接触进口冷链食品员工分析",
        //     "",
        //     "",
        //     "",
        //     "",
        //     "核酸采样信息分析",
        //     "",
        //     "",
        //     "",
        //   ], //第一行表头
        // ];
        const tHeader = [
          // "",
          // "",
          // "员工总数",
          // "如期填报",
          // "延期补录",
          // "延期异常",
          // "暂未填报",
          // "总填报批次数",
          // "如期填报数",
          // "延期补录数",
          // "延期异常",
          "单位业态",
          "注册单位数",
          "员工人数",
          "应采样批次数",
          "总采样批次数",
          "如期采样批次数",
          "延期补录批次数",
          "延期异常批次数",
          "正常未填报批次数",
        ]; //最后一行的表头

        const filterVal = [
          // "bodyindustry",
          // "registerTotal",
          // "staffTotal",
          // "foodStaffFillInTotal",
          // "aryRecordingTotal",
          // "foodStaffAbnormalTotal",
          // "foodStaffNotFilledInTotal",
          // "nucleicAcidBatchTotal",
          // "nucleicAcidFillInTotal",
          // "supplementaryRecordingTotal",
          // "nucleicAcidAbnormalTotal",
          "bodyindustry",
          "registerTotal",
          "staffTotal",
          "shouldAdoptTotal",
          "nucleicAcidBatchTotal",
          "nucleicAcidFillInTotal",
          "supplementaryRecordingTotal",
          "nucleicAcidAbnormalTotal",
          "notFilledInTotal",
        ];

        const data = this.formatJson(filterVal, this.bodyindustryTableDataCopy);
        // const merges = ["A1:A2", "B1:B2", "C1:G1", "H1:K1"];
        excel.export_json_to_excel({
          // multiHeader,
          header: tHeader,
          filename: "单位业态统计_" + new Date().getTime(),
          data,
          // merges,
        });

        //导出excel后
        this.exportLoadingBodyindustry = false;
      });
    },

    //导出采集日期分析表格
    exportExcelCollection() {
      console.log(this.collectionDateSums);
      this.collectionTableDataCopy = JSON.parse(
        JSON.stringify(this.collectionTableData)
      );
      this.collectionTableDataCopy.push({
        categoryDate: this.collectionDateSums[0],
        shouldAdoptTotal: this.collectionDateSums[1],
        nucleicAcidBatchTotal: this.collectionDateSums[2],
        nucleicAcidFillInTotal: this.collectionDateSums[3],
        supplementaryRecordingTotal: this.collectionDateSums[4],
        nucleicAcidAbnormalTotal: this.collectionDateSums[5],
        notFilledInTotal: this.collectionDateSums[6],
      });
      this.exportLoadingCollection = true;
      import("@/utils/Export2Excel").then((excel) => {
        // const multiHeader = [
        //   ["日期类别", "核酸采样信息分析", "", "", ""], //第一行表头
        // ];
        const tHeader = [
          // "",
          // "总填报批次数",
          // "如期填报数",
          // "延期补录数",
          // "延期异常",
          "日期类别",
          "应采样批次数",
          "总采样批次数",
          "如期采样批次数",
          "延期补录批次数",
          "延期异常批次数",
          "正常未填报批次数",
        ]; //最后一行的表头

        const filterVal = [
          // "categoryDate",
          // "nucleicAcidBatchTotal",
          // "nucleicAcidFillInTotal",
          // "supplementaryRecordingTotal",
          // "nucleicAcidAbnormalTotal",
          "categoryDate",
          "shouldAdoptTotal",
          "nucleicAcidBatchTotal",
          "nucleicAcidFillInTotal",
          "supplementaryRecordingTotal",
          "nucleicAcidAbnormalTotal",
          "notFilledInTotal",
        ];

        const data = this.formatJson(filterVal, this.collectionTableDataCopy);
        // const merges = ["A1:A2", "B1:E1"];
        excel.export_json_to_excel({
          // multiHeader,
          header: tHeader,
          filename: "采样日期分析_" + new Date().getTime(),
          data,
          // merges,
        });

        //导出excel后
        this.exportLoadingCollection = false;
      });
    },

    //表格处理
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
  },
};
</script>

<style lang='less' scoped>
.page {
  padding: 10px 20px;
  .btn {
    display: flex;
    justify-content: flex-end;
  }
  .red {
    color: red;
  }
  .green {
    color: green;
  }
}
</style>
